package com.woniuxy.lab.woniu_lab_boss.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniuxy.lab.woniu_lab_boss.common.Result;
import com.woniuxy.lab.woniu_lab_boss.controller.form.AddBaseForm;
import com.woniuxy.lab.woniu_lab_boss.model.Base;
import com.woniuxy.lab.woniu_lab_boss.service.BaseService;
import com.woniuxy.lab.woniu_lab_boss.service.dto.BaseDto;
import com.woniuxy.lab.woniu_lab_boss.service.dto.ParentBaseDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.Pattern;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Silas
 * @since 2023-03-23
 */
@RestController
@RequestMapping("/base")
@Api(tags = "[S]基础镜像相关接口")
@Slf4j
@Validated
public class BaseController {
    @Resource
    private BaseService baseBaseService;


    /**
     * 新增镜像
     * @param addBaseForm 新增镜像参数
     * @return RangeDto
     */
    @ApiOperation("97 新增镜像")
    @PostMapping("/addBase")
    public Result<Object> addBase(@RequestBody @ApiParam("新增镜像参数") @Valid AddBaseForm addBaseForm){
        log.info("开始新增镜像：{}",addBaseForm);
        baseBaseService.addBase(addBaseForm);
        return Result.success(200, "新增镜像成功",null);
    }

    /**
     * 删除镜像
     * @param baseId 镜像Id
     * @return null
     */
    @ApiOperation("98 删除镜像")
    @DeleteMapping("/delBase")
    public Result<Object> delBase(@RequestParam @ApiParam("镜像Id")
                                      @Pattern(regexp = "^[0-9]+$", message = "镜像Id格式不正确")
                                              Integer baseId ){
        log.info("开始删除镜像:{}",baseId);
        baseBaseService.delBase(baseId);
        return Result.success(200, "删除镜像成功",null);
    }

    /**
     * 查询镜像
     */
    @ApiOperation("96 查询镜像")
    @GetMapping("/queryBase")
    public Result<List<ParentBaseDto>> queryBase(){
        log.info("开始查询镜像");
        List<ParentBaseDto> pages =  baseBaseService.queryBase();
        return Result.success(200, "查询镜像成功",pages);
    }

}

